package com.fare.taluo.application.impl.plane.income;

import java.util.ArrayList;
import java.util.List;

import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.dayatang.domain.BaseEntity;
import com.fare.taluo.application.plane.income.FreightPublishApplication;
import com.fare.taluo.core.domain.config.line.FreightPublishEntity;
import com.fare.taluo.vo.core.FreightPublishVO;

/**
 * 接口实现类
 * 
 * @author zengxiangqi
 * 
 */
@Transactional
@Scope("singleton")
@Service("freightPublishApplication")
public class FreightPublishApplicationImpl implements FreightPublishApplication {

	@Override
	public List<FreightPublishVO> findAll() {
		FreightPublishEntity fpe = new FreightPublishEntity();
		List<FreightPublishEntity> entityList = fpe.findAll();
		List<FreightPublishVO> voList = new ArrayList<FreightPublishVO>();
		for (FreightPublishEntity entity : entityList) {
			FreightPublishVO vo = new FreightPublishVO();
			vo.setId(entity.getId());
			vo.setFromCityName(entity.getFromCityName());
			vo.setToCityName(entity.getToCityName());
			vo.setStandardPrice(entity.getStandardPrice());
		/*	vo.setTourist(entity.getTourist());
			vo.setOfficial(entity.getOfficial());
			vo.setBussiness(entity.getBussiness());*/
			vo.setFromCity(entity.getFromCity());
			vo.setToCity(entity.getToCity());
			vo.setMileage(entity.getMileage());
			voList.add(vo);
		}
        System.out.println(voList);
		return voList;
	}

	@Override
	public void remove(Long id) {
		FreightPublishEntity fpe = BaseEntity.get(FreightPublishEntity.class, id);
		fpe.remove();

	}

	@Override
	public void saveOrUpdate(FreightPublishVO vo) {
		FreightPublishEntity fpe = new FreightPublishEntity();
		fpe.setId(vo.getId());
		fpe.setFromCityName(vo.getFromCityName());
		fpe.setToCityName(vo.getToCityName());
		fpe.setStandardPrice(vo.getStandardPrice());
		fpe.setFromCity(vo.getFromCity());
		fpe.setToCity(vo.getToCity());
		fpe.saveOrUpdate(fpe);
	}

	@Override
	public List<FreightPublishVO> findFreightPublishByCondition(int pageNum,
			int pageSize) {
		FreightPublishEntity fpe = new FreightPublishEntity();
		List<FreightPublishEntity> entityList = fpe.findFreightPublishByCondition(pageNum, pageSize);
		List<FreightPublishVO> voList = new ArrayList<FreightPublishVO>();
		for (FreightPublishEntity freightPublishEntity : entityList) {
			FreightPublishVO vo = new FreightPublishVO();
			vo.setId(freightPublishEntity.getId());
			vo.setStandardPrice(freightPublishEntity.getStandardPrice());
			voList.add(vo);
		}
		return voList;
	}
	/**
	 * 根据航线查找运价
	 * 
	 */
	public FreightPublishVO findByLine(String fromCity,String toCity){
		FreightPublishEntity entity =  new FreightPublishEntity().findByLine(fromCity, toCity);
		FreightPublishVO vo = new FreightPublishVO();
		if(entity != null){
			vo.setId(entity.getId());
			vo.setFromCityName(entity.getFromCityName());
			vo.setToCityName(entity.getToCityName());
			vo.setStandardPrice(entity.getStandardPrice());
			vo.setFromCity(entity.getFromCity());
			vo.setToCity(entity.getToCity());
			vo.setMileage(entity.getMileage());
		}
		return vo;
	}
}
